import 'package:flutter/material.dart';
import '../models/health_tip.dart';
import '../services/api_service.dart';

class HealthTipsProvider with ChangeNotifier {
  final ApiService _apiService = ApiService();

  List<HealthTip> _tipsList = [];
  bool _isLoading = false;
  String _errorMessage = '';

  // Getters
  List<HealthTip> get tipsList => _tipsList;
  bool get isLoading => _isLoading;
  String get errorMessage => _errorMessage;

  // 获取健康小妙招
  Future<void> fetchHealthTips(String symptom) async {
    if (symptom.isEmpty) {
      _errorMessage = '请输入症状或关键词';
      notifyListeners();
      return;
    }

    _isLoading = true;
    _errorMessage = '';
    _tipsList = [];
    notifyListeners();

    try {
      final response = await _apiService.getHealthTips(symptom);
      _tipsList = response.tips;
      _isLoading = false;
      notifyListeners();
    } catch (e) {
      _isLoading = false;
      _errorMessage = e.toString();
      notifyListeners();
    }
  }
}
